{extend name="public::base" /}
{block name="body" /}
<div class="row">
    <div class="col-md-8">
        <div class="page-header">
            <h2>用户登录</h2>
        </div>
        <form class="form-horizontal" method="post" id="login">

            <div class="form-group">
                <label for="inputEmail2" class="col-sm-2 control-label">邮箱：</label>
                <div class="col-sm-10">
                    <input type="text" name="email" class="form-control" id="inputEmail2" placeholder="Email">
                </div>
            </div>

            <div class="form-group">
                <label for="inputPassword4" class="col-sm-2 control-label">密码：</label>
                <div class="col-sm-10">
                    <input type="password" name="password" class="form-control" id="inputPassword4" placeholder="Password">
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="button" class="btn btn-primary" id="submit">登录</button>
                </div>
            </div>
        </form>
    </div>
    <script>
        $(function () {
            $("#submit").on('click',function () {
                // alert($('#login').serialize());
                $.ajax({
                    type: 'post',
                    url: "{:url('index/user/loginCheck')}",
                    data: $('#login').serialize(),
                    dataType: 'json',
                    success: function (data) {
                        // if (data.status == 1){
                        //     alert(data.message);
                        //     window.location.href="{:url('index/index/index')}";
                        // }else {
                        //     alert(data.message);
                        //     window.location.href="{:url('index/user/register')}";
                        // }
                        switch (data.status) {
                            case 1:
                                alert(data.message);
                                window.location.href="{:url('index/index')}";
                                break;
                            case 0:
                            case -1:
                                alert(data.message);
                                window.location.back();
                        }
                    }
                })
            })
        })
    </script>
{/block}